<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<%@ page import="java.util.Date"%>
<% String formId = "form_" + new Date().getTime();
   String gridId = "grid_" + new Date().getTime();
   String path = request.getContextPath()+request.getServletPath().substring(0,request.getServletPath().lastIndexOf("/")+1);
%>
<script type="text/javascript" src="<%=request.getContextPath() %>/lib/uplodifyh5/event_common.js"></script>
<script type="text/javascript">
// 保存列表的 选项
var depGroupContents = [{title:'请选择', value: ''}];
var depGroupMap = {};
var hospCodeContents = [{title:'请选择', value: ''}];
$(function () {
	var inputKey; // 搜索框
	var zTreeObj ; // zTree
	var verContents = []; // 版本下拉列表
	// 最近搜索关键字		 搜索结果节点
	var lastValue = "" , nodeList = [] ;
	var depCode ; // 科室编码
	var grid = $('[data-role="departmentGrid"]');
    var form = $("[name='departmentForm']");
    var hasDrg_clispec ; // 有临床专业与ADRG的对照关系

 	// 加载并初始化
    function querySpecTreeData(depCode,version,point){
    	$.post(contextPath + "/Department/initeSpecTree.dhc",{"depCode":depCode,'verCode':version}).done(function(data) {
    		hasDrg_clispec = data.data.data.msg ;
    		var ztreenode=data.data.data.nodeList ;
    		loadZtreeFun(ztreenode) ;
    		
    	}) ;
    }
    
    
 // 获取系统配置的版本号
    function getVerCode(versionAll){
    	$.post(contextPath + "/systemConfig/getConfigByCode.dhc" ,{"cfgCode":"GROUP_VER"}).done(function(data){
    		var verCode = data.data ;
    		$.each(versionAll,function(i,n){
         	   // 将系统配置的分组器版本置为选中状态
         	   if(n.verCode == verCode){
         		   verContents.push({title:n.verDesc, value:n.verCode,selected:true});
         	   } else {
         		   verContents.push({title:n.verDesc, value:n.verCode,selected:false});
         	   }
       	  });
    	})
    }
 	
	PageLoader = {
	    initSearchPanel:function(){	    	
	    	/* 加载所有院区列表 */
	    	$.get('${pageContext.request.contextPath}/Department/findAllHosp.dhc').done(function(result){
                   if(result.success ){
                       var hospCodeAll = result.data;
                       $.each(hospCodeAll,function(i,n){
                    	   hospCodeContents.push({title:n.HOSP_NAME, value:n.HOSP_CODE});
                  		});
      	             form.find('#hospCodeID').select({
      			           title: '请选择',
      			           contents: hospCodeContents
      			      }).on('change',function(){
      			          form.find('#hospCodeID_').val($(this).getValue());
      			      });
                  }
           });
	    	/* 加载所有科室组列表 */
	    	$.get('${pageContext.request.contextPath}/DepGroup/findAllDepGroup.dhc').done(function(result){
                   if(result.success ){
                       var depGroupAll = result.data;
                       $.each(depGroupAll,function(i,n){
                    	   depGroupContents.push({title:n.depGroupDesc, value:n.depGroupCode});
                    	   depGroupMap[n.depGroupCode] = n.depGroupDesc;
                  		});
      	             form.find('#depGroupCodeID').select({
      			           title: '请选择',
      			           contents: depGroupContents
      			      }).on('change',function(){
      			          form.find('#depGroupCodeID_').val($(this).getValue());
      			      });
                  }
           });
	    	/* 加载版本下拉列表 */ 
	    	$.get(contextPath + '/DRGVersion/findAllVersion.dhc').done(function(result){
	              if(result.success ){
	                   versionAll = result.data;
	                   getVerCode(versionAll);
	              }
	       });
	    	
	    	var isOpeCon = [{title:'请选择', value: ''},{title:'是', value: 1},{title:'否', value: 0}];
	    	form.find('#isOpeDepID').select({
		           title: '请选择',
		           contents: isOpeCon
		      }).on('change',function(){
		          form.find('#isOpeDepID_').val($(this).getValue());
		      });
	    	
	    },
	    
	    initGridPanel: function(){
	         var self = this;
	         var width = 112;
	         return grid.grid({
	                identity:"depCode",
	                buttons: [
	                        {content: '<button class="btn btn-primary" type="button"><span class="glyphicon glyphicon-plus"><span>添加</button>', action: 'add'},
	                        {content: '<button class="btn btn-success" type="button"><span class="glyphicon glyphicon-edit"><span>修改</button>', action: 'modify'},
	                        {content: '<button class="btn btn-danger" type="button"><span class="glyphicon glyphicon-remove"><span>删除</button>', action: 'delete'},
	                        {content: '<button class="btn btn-info" type="button"><span class="glyphicon glyphicon-th-large"><span>选择临床专业</button>', action: 'selCliSpec'},
	                        {content: '<button class="btn btn-primary" type="button" title="一键同步首页中院区信息"><span class="glyphicon glyphicon-repeat"><span>一键同步</button>', action: 'synchro'},
	                        {content: '<button class="btn btn-success" type="button"><span class="glyphicon glyphicon-cloud-upload"><span>科室数据导入</button>', action: 'dataImport'}
	                        ],
	                url:"${pageContext.request.contextPath}/Department/pageJson.dhc",
	                columns: [
								{ title: '科室显示顺序', name: 'depOrder', width: 100},
								{ title: '科室代码', name: 'depCode', width: width},
								{ title: '科室名称', name: 'depName', width: width},
								{ title: '科室类型', name: 'depType', width: width,
								  render: function (rowdata, name, index) {
									  if(rowdata.depType=="E"){
										  return "执行科室";  
									  }else if(rowdata.depType=="S"){
										  return "职能科室";   
									  }else{
										  return '';
									  }
	                               }
								},
								{ title: 'HIS科室代码', name: 'depHisCode', width: width},
								{ title: 'HIS科室名称', name: 'depHis', width: width}, 
								{ title: '负责人', name: 'depLeader', width: 90},
								{ title: '联系电话', name: 'depTelephone', width: width },
								{ title: '所属院区', name: 'hospDesc', width: width },
								{ title: '所属科室组', name: 'parDepGroupCode', width: width, render: function (rowdata, name, index) {
									return depGroupMap[rowdata.parDepGroupCode];
                                }},
								{ title: '覆盖DRG病组', name: 'countDRG', width: 80, render: function (rowdata, name, index) {
                                    var param = '"' + rowdata.depCode + '"' ;
                                    var h = "<a href='javascript:openSpecPage(" + param + ")'>查看</a>"; 
                                    //var h = "<a href='javascript:openSpecPage(" + param + ")'>"+rowdata.countDRG+"</a>"; 
                                    return h ;
                                } },
								{ title: '是否手术科室', name: 'isOpeDep', width: 90,
									render: function (rowdata, name, index){
										if(rowdata.isOpeDep==0){
											return "否";
										}else if(rowdata.isOpeDep==1){
											return "是";
										}
	                                 }
								},
								{ title: '床位数', name: 'depBedCnt', width: 70},
								{ title: '医生数', name: 'depDoctorCnt', width: 70},
								{ title: '操作', width: 160, render: function (rowdata, name, index)
	                                 {
	                                     var param = '"' + rowdata.depCode + '"';
	                                     var h = "<a href='javascript:openClinicsPage(" + param + ")'>查看所辖医师</a>";
	                                     return h;
	                                 }
	                             }
	                ]
	         }).on({
	                   'add': function(){
	                       self.add($(this));
	                   },
	                   'modify': function(event, data){
	                        var indexs = data.data;
	                        var $this = $(this);
	                        if(indexs.length == 0){
	                            drgUI.warning('请选择一条记录进行修改!');
	                            return;
	                        }
	                        if(indexs.length > 1){
	                            drgUI.warning('只能选择一条记录进行修改!');
	                            return;
	                        }
	                       self.modify(data.item[0],indexs[0], $this);
	                    },
	                    'selCliSpec': function(event, data){
	                        var indexs = data.data;
	                        var $this = $(this);
	                        if(indexs.length == 0){
	                            drgUI.warning('请选择一条记录进行修改!');
	                            return;
	                        }
	                        if(indexs.length > 1){
	                            drgUI.warning('只能选择一条记录进行修改!');
	                            return;
	                        }
	                       self.selCliSpec(data.item[0],indexs[0], $this);
	                    },
	                   'delete': function(event, data){
	                        var indexs = data.data;
	                        var $this = $(this);
	                        if(indexs.length == 0){
	                            drgUI.warning('选择要删除的记录！');
	                            return;
	                        }
	                        var remove = function(){
	                            self.remove(indexs, $this);
	                        };
	                        drgUI.confirm({
	                            content: '确定要删除所选记录吗?',
	                            callSure: remove
	                        });
	                   },
	                   'synchro': function(event, data){
	                	    var indexs = data.data;
	                        var $this = $(this);
	                        if(indexs.length == 0){
	                            drgUI.warning('请至少选择一条记录进行同步!');
	                            return;
	                        }
	                     self.synchro(indexs, $this);
	                   },
	                   'dataImport':function(){
	                	   self.dataImport($(this));
	                   }
	         });
	    },
	   synchro: function(ids,grid){
			var data = [{ name: 'depCodes', value: ids.join(',') }];
            drgUI.confirm({
                content: '是否将所选科室的院区对应关系同步到首页中病例的院区信息中?',
                callSure: function(){
     	    	   var self = this;
    	    	   $.post('${pageContext.request.contextPath}/Department/synchro.dhc', data).done(function(result){
    	    		    if(result.success ){
    	    		    	 drgUI.success('同步成功!');
    	    		    }else{
    	    		    	 drgUI.error('同步失败！');
    	    		    }
    	    	   });
                }
            });	    	
	    }, 
	    dataImport:function(grid){
	    	$('#uploadifive-departmentImport input[type="file"]:last').click() ; 
	    },
	    add: function(grid){
	        var self = this;
	        var dialog = $('<div class="modal fade"><div class="modal-dialog">'
	        	+'<div class="modal-content"><div class="modal-header"><button type="button" class="close" '
	        	+'data-dismiss="modal" aria-hidden="true">&times;</button>'
	        	+'<h4 class="modal-title">新增</h4></div><div class="modal-body">'
	        	+'<p>One fine body&hellip;</p></div><div class="modal-footer">'
	        	+'<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>'
	        	+'<button type="button" class="btn btn-success" id="save">保存</button></div></div>'
	        	+'</div></div>');
	        $.get('<%=path%>/Department-add.jsp').done(function(html){
	            dialog.modal({
	                keyboard:false
	            }).on({
	                'hidden.bs.modal': function(){
	                    $(this).remove();
	                }
	            }).find('.modal-body').html(html);
	            self.initPage(dialog.find('form'));
	        });
	        dialog.find('#save').on('click',{grid: grid}, function(e){
	              if(!Validator.Validate(dialog.find('form')[0],3))return;
	              var depOrder = $("#depOrderID").val();
	             // var depGroupCode = $("#depGroupCode_ #depGroupCodeID_").val();
	              $.post('${pageContext.request.contextPath}/Department/isOrderExist.dhc',
	            		  {'order':depOrder}).done(function(result){
	            	  if(result){
	            		  drgUI.error('显示顺序已存在，请重新输入!');
	            	  }else{
	            		  $.post('${pageContext.request.contextPath}/Department/add.dhc', dialog.find('form').serialize()).done(function(result){
	   	                   if(result.success ){
	   	                        dialog.modal('hide');
	   	                        e.data.grid.data('koala.grid').refresh();
	   	                     	drgUI.success('保存成功!');
	   	                     	drgUI.warning('如果科室对应院区有所变动，请使用一键同步功能进行及时同步!');
	   	                    }else{
	   	                    	 drgUI.error(result.errorMessage);
	   	                     }
	   	              	});
	            	  }
	              });
	        });
	    },
	    
	    modify: function(item,id, grid){
	        var self = this;
	        var dialog = $('<div class="modal fade"><div class="modal-dialog"><div class="modal-content"><div class="modal-header"><button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button><h4 class="modal-title">修改</h4></div><div class="modal-body"><p>One fine body&hellip;</p></div><div class="modal-footer"><button type="button" class="btn btn-default" data-dismiss="modal">取消</button><button type="button" class="btn btn-success" id="save">保存</button></div></div></div></div>');
	        $.get('<%=path%>/Department-update.jsp').done(function(html){
	               dialog.find('.modal-body').html(html);
	               self.initPage(dialog.find('form'));
	               dialog.find("#depOrderIDUpdate").val($.trim(item.depOrder));
	               dialog.find("#depNameIDUpdate").val(item.depName);
	               dialog.find("#depHisCodeIDUpdate").val(item.depHisCode);
	               dialog.find("#depHisIDUpdate").val(item.depHis);
	               dialog.find("#depCodeIDUpdate").val(item.depCode);
	               dialog.find("#depTelephoneIDUpdate").val(item.depTelephone);
	               dialog.find("#depLeaderIDUpdate").val(item.depLeader);
	               dialog.find("#validStatesIDUpdate").val(item.validStates);
	               dialog.find("#depDoctorCntIDUpdate").val(item.depDoctorCnt);
	               dialog.find("#depBedCntIDUpdate").val(item.depBedCnt);
	               dialog.find("#parDepGroupCodeUpdate").setValue(item.parDepGroupCode);
	               dialog.find("#isOpeDepID").setValue(item.isOpeDep);
	               dialog.find("#hospCodeID").setValue(item.parHospCode);
	               dialog.find("#depTypeID").setValue(item.depType);
	                dialog.modal({
	                    keyboard:false
	                }).on({
	                    'hidden.bs.modal': function(){
	                        $(this).remove();
	                    }
	                });
	                dialog.find('#save').on('click',{grid: grid}, function(e){
	                    if(!Validator.Validate(dialog.find('form')[0],3))return;
	                     var depOrder = $("#depOrderIDUpdate").val();
	  	              //var depGroupCode = $("#depGroupCode_ #depGroupCodeID_").val();
	  	              	var depCode = item.depCode;
	  	              $.post('${pageContext.request.contextPath}/Department/isOrderExist.dhc',
	  	            		  {'order':depOrder,'code':depCode}).done(function(result){
	  	            	  if(result){
	  	            		drgUI.warning('显示顺序已存在，请重新输入!');
	  	            	  }else{
	  	            		$.post('${pageContext.request.contextPath}/Department/update.dhc?depCode='+id, dialog.find('form').serialize()).done(function(result){
		                        if(result.success){
		                            dialog.modal('hide');
		                            e.data.grid.data('koala.grid').refresh();
		                            drgUI.success('保存成功!');
		                         	drgUI.warning('如果科室对应院区有所变动，请使用一键同步功能进行及时同步!');
		                        }else{
		                            drgUI.error(result.actionError);
		                        }
		                    });
	  	            	  }
	  	              }); 
	                });
	        });
	    },
	    
	    selCliSpec: function(item,id, grid) {
	        var self = this;
	        depCode = item['depCode'] ;
	        var dialog = $('<div class="modal fade"><div class="modal-dialog"><div class="modal-content"><div class="modal-header"><button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button><h4 class="modal-title">选择DRG病组</h4></div><div class="modal-body"><p>One fine body&hellip;</p></div><div class="modal-footer"><button type="button" class="btn btn-default" data-dismiss="modal">取消</button><button type="button" class="btn btn-success" id="save">保存</button></div></div></div></div>');
	        $.get(contextPath + '/pages/domain/Department-selSepc.jsp').done(function(html){
	               dialog.find('.modal-body').html(html);
	               self.initPage(dialog.find('form'));
	               var version = dialog.find('#versionCodeID > input[type="hidden"]').val() ;
	               dialog.find(".modal-dialog").css("width","640px");
	               dialog.find(".modal-footer").css("margin-top","0px");
	       		   dialog.find("#echartcq4").css("width","600px");
	               dialog.modal({
	                    keyboard:false
	                }).on({
	                	"shown.bs.modal":function(){
	                		querySpecTreeData(depCode,version,$(this)) ;
	                		/* $(".loadingSpec").css("display","none") ; */
	                		/* $("#treeSpec").css("display","block") ; */
	                	},
	                
	                    'hidden.bs.modal': function(){
	                        $(this).remove();
	                    }
	                });
	               
		            inputKey = dialog.find('#searchDiv > span > input') ;
		            inputKey.bind("focus", focusKey)
		 			.bind("blur", blurKey)
		 			.bind("propertychange", searchNode)
		 			.bind("input", searchNode); 
	                 
	                dialog.find('#save').on('click',{grid: grid}, function(e){
	                	var adrgs  ;
	                	var nodes = zTreeObj.getCheckedNodes(true);
	                	var cliSpecArr = new Array() ;
	                	for (var i = 0; i < nodes.length; i++) {
	                		if( nodes[i].level == 3){
	                			// 临床专业#DRG编码
	                			cliSpecArr.push(nodes[i].id);
	                		}
	                	}
	                	var version = $('#versionCodeID > input[type="hidden"]').val() ;
	                	if( version == "" ) {
	  	            		drgUI.error('请选择DRG分组器版本!');
	  	            	} else if( !hasDrg_clispec ) {
	  	            		drgUI.error('没有临床专业与该版本drg的对照关系，请在临床专业管理维护!');
		  	            }  else {
	  	            		$.post(contextPath + '/Department/saveSelCliSpec.dhc',  {"depCode":depCode,"verCode":version,"cliSpecArr":cliSpecArr}).done(function(result){
		                         if(result.success){
		                            dialog.modal('hide');
		                            e.data.grid.data('koala.grid').refresh();
		                            drgUI.success('保存成功!');
		                        }else{
		                            drgUI.error('保存失败!');
		                        } 
		                    });
	  	            	  }
	               });
	        });
	    },
	    initPage: function(form){
	              form.find('.form_datetime').datetimepicker({
	                   language: 'zh-CN',
	                   format: "yyyy-mm-dd",
	                   autoclose: true,
	                   todayBtn: true,
	                   minView: 2,
	                   pickerPosition: 'bottom-left'
	               }).datetimepicker('setDate', new Date());//加载日期选择器
	              
	               form.find('.select').each(function(i){
	                    var select = $(this);
	                    var idAttr = select.attr('id');
	                    var  selectD ;
	                    if(idAttr == "versionCodeID") {
	                    	selectD = select.select({
		                        title: '请选择',
		                        contents: verContents
		                    });
	                    } else if(idAttr =='hospCodeID'){
	                    	selectD = select.select({
		                        title: '请选择',
		                        contents: hospCodeContents
		                    });
	                    }else{
	                    	selectD = select.select({
		                        title: '请选择',
		                        contents: depGroupContents
		                    });
	                    }
	                    selectD.on('change', function(){
	                    	$("#searchDiv > span > input").val("") ;
	                        form.find('#'+ idAttr + '_').val($(this).getValue());
	                        if(idAttr == "versionCodeID"){
	                        	var version = $(this).getValue() ;
	                        	querySpecTreeData(depCode,version,$(this));
	                        }
	                    });
	               });
	               var isOpeCon = [{title:'请选择', value: ''},{title:'是', value: 1},{title:'否', value: 0}];
	               form.find('#isOpeDepID').select({
	            	   title: '请选择',
	   		           contents: isOpeCon
   		           }).on('change',function(){
   		        	   form.find('#isOpeDepID_').val($(this).getValue());
	        	   });
	   	    	/* 加载科室类型 */
	 	    	  var depTypes = [{title:'执行科室', value: 'E'},{title:'职能科室', value: 'S'}];
	 	           form.find('#depTypeID').select({
	 		           title: '请选择',
	 		           contents: depTypes
	 		      }).on('change',function(){
	 		          form.find('#depTypeID_').val($(this).getValue());
	 		      });
	    },
	    
	    remove: function(ids, grid){
	    	var data = [{ name: 'depCodes', value: ids.join(',') }];
	    	$.post('${pageContext.request.contextPath}/Department/delete.dhc', data).done(function(result){
	                        if(result.success){
	                            grid.data('koala.grid').refresh();
	                            drgUI.success('删除成功!');
	                        }
	                        else{
	                            drgUI.error(result.errorMessage);
	                        }
	    	});
	    }
	    
	}
	
	PageLoader.initSearchPanel();
	PageLoader.initGridPanel();
	// 下载按钮
	var downloadBtn = '<div class="btn-clickable">' ;
	downloadBtn+='<a href="download/depPartment.xlsx" class="link text-sm" style = "text-decoration:none;color:#fff">' ;
	downloadBtn+='<i class="fa fa-download"></i>&nbsp;下载模版' ;
	downloadBtn+='</a>' ;
	downloadBtn+='</div>' ;
	$(<%=gridId%>).find("thead > tr > th").append(downloadBtn) ;
	
	$('#'+tabId+' #departmentImport').uploadifive({
		'uploadScript' : contextPath + '/fileUpload/filesUpload.dhc',
        'height': 37,
        'width' :125,
        'auto'  : true,//是否自动开始
        'uploadLimit' : 100, //一次同步上传的文件数目     
        'fileSizeLimit' : '500MB', //单个文件大小，0为无限制，可接受KB,MB,GB等单位的字符串值     
        'queueSizeLimit' : 100, //队列中同时存在的文件个数限制
        'fileObjName':'file',
        'removeCompleted': true,  //是否完成后移除序列，默认为true
        'removeTimeout' : '5',  //上传完成后队列多长时间后消失。默认 3秒    需要：removeCompleted : true,时使用
        'progressData' :'percentage',//设置上传进度显示方式，percentage显示上传百分比，speed显示上传速度
        'buttonText' : '<i class="fa fa-folder-open fa-lg"></i>&nbsp;&nbsp;选择文件',
        'buttonClass': 'uploadifyH5_btn',
        'fileType' : '*.xls; *.xlsx; *.xml; *.dbf',//允许上传的文件格式
        'multi'    : true,//是否支持多文件上传
        'method'   :'post',//提交方式
        'debug':false,
        //当点击文件队列中文件的关闭按钮或点击取消上传时触发
        'onCancel': function(){ },
        'onUpload': function(filesToUpload) {
        	$("#uploadifive-departmentImport-queue").css("display","none") ;
        },
      	//返回一个错误，选择文件的时候触发  
        'onSelectError':  function() {
            drgUI.error('文件上传失败!');
        },
      	//检测FLASH失败调用  
        'onFallback':function() {
             drgUI.error('浏览器检测不到兼容版本的HTML5');
        }, 
        'onUploadError' : uploadify_onUploadError,
        'onQueueComplete':function(queueData){
        	$.post(contextPath+'/fileUpload/departmentImport.dhc').done(function(result){
        		if(result.hasErrors){
        			drgUI.alert(result.errorMessage,function(){
            			$('[data-role="departmentGrid"]').grid('refresh');
            		});
        		}
        		else{
        			drgUI.alert(result.data,function(){
            			$('[data-role="departmentGrid"]').grid('refresh');
            		});
        		}
        	});
        }
    });
	$("#uploadifive-departmentImport").css("display","none") ;
	form.find('#search').on('click', function(){
            if(!Validator.Validate(document.getElementById("<%=formId%>"),3))return;
            var params = {};
            form.find('input').each(function(){
                var $this = $(this);
                var name = $this.attr('name');
                if(name){
                    params[name] = $this.val();
                }
            });
            grid.getGrid().search(params);
        });
	/*ztree插件*/
	var cheeckedNodeId = null ;
	var loadZtreeFun = function(ztreenode) {
		var fontCss = {};
		var setting = {
		        data:{
		            simpleData:{
		         	 enable: true,
		         	 idKey:  "id",
		         	 pIdKey: "pid",
		         	 rootPId:"0"
		            }  
		        },  
		        check: {
		            enable: true ,
		        },
		        view :{ 
		            showIcon: false,  
		            fontCss: getFontCss
		        },
		        callback: {
		        	beforeCheck: beforeCheckDep
				}
		};
		
		function beforeCheckDep(treeId, treeNode) {
			// 科室不能跨专业选择DRGs
			// 当前选中的节点与已选中的节点不是一个父节点则取消选中
			if(cheeckedNodeId != treeNode.getPath()[0].id) {
				cheeckedNodeId = treeNode.getPath()[0].id ;
				var zTree = $.fn.zTree.getZTreeObj("treeSpec");
				zTree.checkAllNodes(false);
			}
			cheeckedNodeId = treeNode.getPath()[0].id ;
		}
		
		function getFontCss(treeId, treeNode) {
			return (!!treeNode.highlight) ? {color:"#6633FF", "font-weight":"bold"} : {color:"#333", "font-weight":"normal"};
		}
		zTreeObj = $.fn.zTree.init($("#treeSpec"),setting,ztreenode);
	}
	
	
	function focusKey(e) {
		if (inputKey.hasClass("empty")) {
			inputKey.removeClass("empty");
		}
	}
	function blurKey(e) {
		if (inputKey.get(0).value === "") {
			inputKey.addClass("empty");
		}
	}
	// adrg搜索
	function searchNode(e) {
		var value = $.trim(inputKey.get(0).value);
		var keyType = "name";
		if (inputKey.hasClass("empty")) {
			value = "";
		}
		if (lastValue === value) return;
		lastValue = value ;
		updateNodes(false);
		nodeList = zTreeObj.getNodesByParamFuzzy(keyType, value);
		if (value == "" || nodeList.length == 0 ) {
			zTreeObj.expandAll(false);
			return;
		}
	    updateNodes(true);
    }
	// 更新节点高亮状态
	function updateNodes(highlight) {
		for( var i=0, l=nodeList.length; i<l; i++) {
			nodeList[i].highlight = highlight;
			zTreeObj.updateNode(nodeList[i]);
			// 展开搜索到的节点的父节点
			// 设置focus = true 表示 展开 / 折叠 操作后，通过设置焦点保证此焦点进入可视区域内
			var focus = false ;
			if( i == 0 && highlight ) {
				focus = true ;
			}
			zTreeObj.expandNode(nodeList[i].getParentNode(),highlight,focus,false);
		}
	}

	function filter(node) {
		return !node.isParent && node.isFirstNode;
	}
});

var openClinicsPage = function(depCode){
        var dialog = $('<div class="modal fade"><div class="modal-dialog"><div class="modal-content"><div class="modal-header"><button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button><h4 class="modal-title">查看所辖医师</h4></div><div class="modal-body"><p>One fine body&hellip;</p></div><div class="modal-footer"><button type="button" class="btn btn-info" data-dismiss="modal">返回</button></div></div></div></div>');
        $.get('<%=path%>/Department-view.jsp').done(function(html){
               dialog.find('.modal-body').html(html);
               $.get( '${pageContext.request.contextPath}/Department/findDoctorInDep/' + depCode + '.dhc').done(function(json){
                        json = json.data;
                        if(json =="")
                        	json="无";
                        dialog.find('#ClinicInfoID').html(json);
               });
                dialog.modal({
                    keyboard:false
                }).on({
                    'hidden.bs.modal': function(){
                        $(this).remove();
                    }
                });
        });
}

var openSpecPage = function(depCode) {
	var dialog = $('<div class="modal fade"><div class="modal-dialog"><div class="modal-content"><div class="modal-header"><button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button><h4 class="modal-title">查看ADRG</h4></div><div class="modal-body"><p>One fine body&hellip;</p></div><div class="modal-footer"><button type="button" class="btn btn-info" data-dismiss="modal">返回</button></div></div></div></div>');
    $.get('<%=path%>/Department-spec-view.jsp').done(function(html){
           dialog.find('.modal-dialog').css("width","800px");
           dialog.find('.modal-body').html(html);
            dialog.modal({
                keyboard:false
            }).on({
                'hidden.bs.modal': function(){
                    $(this).remove();
                } ,
                'shown.bs.modal': function(){
                	var coloums = [	 
	       							{
	       								"data": "PARSPEC_CODE","title":"临床专业编号"
	       							},
	       							{
	       								"data": "SPEC_DESC","title":"临床专业名称"
	       							},
	       							{
	       								"data": "DRG_CODE","title":"DRG编号"
	       							},
	       							{
	       								"data": "DRG_DESC","title":"DRG名称"
	       							},
	       							{
	       								"data": "ADRG_CODE","title":"ADRG编号"
	       							},
	       							{
	       								"data": "ADRG_DESC","title":"ADRG名称"
	       							},
	       							{
	       								"data": "MDC_CODE","title":"MDC编号"
	       							},
	       							{
	       								"data": "MDC_DESC","title":"MDC名称"
	       							}
            					] ;
                  var paramsDataTables = {} ;
                  $.get( contextPath + '/Department/findSpecBydepCode/' + depCode + '.dhc').done(function(data){
               	   var drgData = data.data ;
               	   var versionTabContent = dialog.find('#versionTabContent');
               	   if(drgData.length == 0){
               		   dialog.find('.modal-body').html('<p class="text-center"> 无数据 </p>') ;
               	   } else {
               		   var table = $('<div class="tab-pane fade " id="version'+i+'"><table id="tabver'+i+'" class="table table-hover"></table></div>') ;
               		   versionTabContent = dialog.find('#versionTabContent');
                       var versionTab = dialog.find('#versionTab') ;
               		   for(var i = 0 ; i < drgData.length ; i++ ){
                       	     var table1 = $('<div class="tab-pane fade in active" id="version'+i+'"><table id="tabver'+i+'" class="table table-hover"></table></div>') ;
                       	     var table2 = $('<div class="tab-pane fade " id="version'+i+'"><table id="tabver'+i+'" class="table table-hover"></table></div>') ;
                       	        versionTabContent = dialog.find('#versionTabContent');
                                var versionTab = dialog.find('#versionTab') ;
                                  if(i==0){
                                     versionTab.append($('<li class="active"><a href="#version'+i+'" data-toggle="tab">'+drgData[i].verDesc+'</a></li>'));
                                     versionTabContent.append(table1);
                                  } else {
                                     versionTab.append($('<li><a href="#version'+i+'" data-toggle="tab">'+drgData[i].verDesc+'</a></li>'));
                              	     versionTabContent.append(table2);
                                  }
                                  
                                  if(drgData[i].version == sysConfig.GROUP_VER) {
                                	  versionTab.find("li:last a").text(drgData[i].verDesc+"(当前版本)") ;
                                  }
                                data = drgData[i].drgList ; 
                                dialog.find('#tabver'+i+'').dataTableBasic(coloums,data,paramsDataTables);
                   	   	   }
               	       }
                   });
                } 
            });
    });
}
</script>

<style>
     /* datatables  不显示导出按钮 */ 
	.DTTT_container,.dataTables_length {
		display:none
	}
	
	body > div.modal.fade.in > div > div > div.modal-body{
	padding-bottom: 10px;
	}
	
</style>

</head>
<body>
<div style="width:98%;margin-right:auto; margin-left:auto; padding-top: 15px;">
<!-- search form -->
<%-- <form name="departmentForm" id=<%=formId%> target="_self" class="form-horizontal">
<table border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td style="width:95%">
    <div class="form-group">
	    <label class="control-label" style="width:80px;float:left;">科室名称:&nbsp;</label>
	    <div style="margin-left:15px;float:left;">
	    	<input name="depName" class="form-control" type="text" style="width:150px;" id="depNameID"  />
	    </div>
	    <label class="control-label" style="width:80px;float:left;">所属院区:&nbsp;</label>
        <div style="margin-left:15px;float:left;">
        	<div class="btn-group select" id="hospCodeID"></div>
	        <input type="hidden" id="hospCodeID_" name="parHospCode" />
        </div>
	    <label class="control-label" style="width:80px;float:left;">所属科室组:&nbsp;</label>
        <div style="margin-left:15px;float:left;">
        	<div class="btn-group select" id="depGroupCodeID"></div>
	        <input type="hidden" id="depGroupCodeID_" name="parDepGroupCode" />
        </div>
        <label class="control-label" style="width:100px;float:left;">是否手术科室:&nbsp;</label>
        <div style="margin-left:15px;float:left;">
        	<div class="btn-group select" id="isOpeDepID"></div>
	        <input type="hidden" id="isOpeDepID_" name="isOpeDep" />
        </div>
    
    	<label class="control-label" style="width:80px;float:left;">负责人:&nbsp;</label>
	    <div style="margin-left:15px;float:left;">
            <input name="depLeader" class="form-control" type="text" style="width:120px;" id="depLeaderID"  />
        </div>
    </div>
    </td>
    <td style="vertical-align: bottom;"><button id="search" type="button" style="position:relative; margin-left:35px; top: -15px" class="btn btn-primary"><span class="glyphicon glyphicon-search"></span>&nbsp;查询</button></td>
  </tr>
</table>
</form> --%>
<form name="departmentForm" id=<%=formId%> target="_self" class="form-horizontal">
	<div class="container-fluid" style="margin-bottom: 10px;"> 
	<div class="row">
		<div class="form-group col-md-2">
			<label class="control-label" style="width:100px;">科室名称:&nbsp;</label>
		    <input name="depName" class="form-control" type="text" style="width:150px;" id="depNameID"  />
		    
		</div>
		<div class="form-group col-md-2">
			<label class="control-label" style="width:100px;">所属院区:&nbsp;</label>
	        <div class="btn-group select" id="hospCodeID"></div>
		    <input type="hidden" id="hospCodeID_" name="parHospCode" />
		</div>
		<div class="form-group col-md-2">
			<label class="control-label" style="width:100px;">所属科室组:&nbsp;</label>
	        <div class="btn-group select" id="depGroupCodeID"></div>
		    <input type="hidden" id="depGroupCodeID_" name="parDepGroupCode" />
		</div>
		<div class="form-group col-md-2">
			<label class="control-label" style="width:100px;">是否手术科室:&nbsp;</label>
	        <div class="btn-group select" id="isOpeDepID"></div>
		    <input type="hidden" id="isOpeDepID_" name="isOpeDep" />
		</div>
		<div class="form-group col-md-2">
			<label class="control-label" style="width:100px;">负责人:&nbsp;</label>
		    <input name="depLeader" class="form-control" type="text" style="width:120px;" id="depLeaderID"  />
		</div>
		<div class="form-group col-md-1">
			<label class="control-label" style="width:100px;float:left; color:white;">隐藏&nbsp;</label>
			<button id="search" type="button" style="" class="btn btn-primary"><span class="glyphicon glyphicon-search"></span>&nbsp;查询</button>
		</div>
	</div>
	</div>
</form>

<div><input id="departmentImport" type="file" name="departmentImport" style="display: none;"/></div>
<!-- grid -->
<div  data-role="departmentGrid" id=<%=gridId%>></div>
</div>
</body>
</html>
